package com.iafme.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.operator.Equal;
import cn.zhxu.bs.util.MapBuilder;
import cn.zhxu.bs.util.MapUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.MemberMessageReqDTO;
import com.iafme.dto.req.MessageReqDTO;
import com.iafme.dto.res.MemberMessageResDTO;
import com.iafme.dto.res.MessageResDTO;
import com.iafme.service.MessageService;
import com.systemframework.constants.Constants;
import com.systemframework.sys.dto.request.common.PageResponseDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2025/3/3 21:30
 */
@RestController
@RequestMapping(value = "/message")
@AllArgsConstructor
public class MessageController {

    private final MessageService messageService;

    @PostMapping(value = "/lists")
    public Page<MessageResDTO> lists(@RequestBody MessageReqDTO dto){

        return messageService.lists(dto);
    }

    private final BeanSearcher beanSearcher;

    @GetMapping(value = "/memberMessageList")
    public List<MemberMessageResDTO> memberMessageList(){
        MapBuilder op = MapUtils.builder().field(MemberMessageResDTO::getMemberId, StpUtil.getLoginIdAsInt()).op(Equal.class);
        return beanSearcher.searchList(MemberMessageResDTO.class,op.build());
    }

    @PostMapping(value = "/memberMessageRead")
    public String memberMessageRead(@RequestBody List<MemberMessageReqDTO> reqDTOList){
        messageService.memberMessageRead(reqDTOList);
        return Constants.SUCCESS;
    }
    @PostMapping(value = "/memberMessageDelete")
    public String memberMessageDelete(@RequestBody List<MemberMessageReqDTO> reqDTOList){
        messageService.memberMessageDelete(reqDTOList);
        return Constants.SUCCESS;
    }

}
